package com.hhf.feiojcommonservice.utils;

/**
 * @Author hhf
 * @Date 2024/11/6
 * @Description 全局保存用户id
 */
public class UserIdContext {

    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();


    /**
     * 保存当前用户信息至threadLocal
     * @param userId
     */
    public static void setUserId(Long userId){
        threadLocal.set(userId);
    }

    /**
     * 获取当前用户信息
     */
    public static Long getUserId(){
        return threadLocal.get();
    }

    /**
     * 移除当前用户信息
     */
    public static void removeUserId(){
        threadLocal.remove();
    }

}
